package com.touchalachs.core.ui;

import android.graphics.Canvas;
import android.graphics.Paint;
import android.graphics.Point;
import android.graphics.Rect;

public class Button extends TippableBasicUIElement {

	private static final int  BORDER = 5; //px
	private final ButtonListener listener;
	private volatile String text;
	private volatile int fontSize = 24;
	
	/**
	 * relative size 0..100
	 */
	public Button(int x, int y, int w, int h, String text, Point screenSize, ButtonListener listener) {
		super(x, y, w, h, screenSize);
		this.text = text;
		this.listener = listener;
	}

	@Override
	public void draw(Canvas canvas) {
		Paint p = new Paint();
		p.setARGB(255, 128, 128, 128);
		canvas.drawRect(getDimension(), p);
		p.setARGB(255, 64, 64, 64);
		canvas.drawRect(new Rect(getDimension().left+BORDER, getDimension().top+BORDER, getDimension().right-BORDER, getDimension().bottom-BORDER), p);
		p.setARGB(255, 192, 192, 192);
		p.setTextSize(fontSize);
		canvas.drawText(text, getX()+BORDER+1, getY()+2+fontSize+BORDER, p);
	}


	@Override
	public boolean tipp(int x, int y) {
		return listener.onTipp(this);
	}



}
